<?php
namespace helper;

use idea\log\LogDb;
use idea\saf;

/**
 * Log class file
 * 日志处理类
 * @author 宋欢 <iphper@yeah.net>
 * @version $Id: Log.php 1 2013-04-05 19:53:06Z huan.song $
 * @package helper
 * @since 1.0
 */
class Log extends saf\Log
{
	/**
	 * 打印warning日志，日志存入数据库
	 * @param mixed $event
	 * @param string $method
	 * @param integer $errno
	 * @return void
	 */
	public static function dbWarning($event, $errno = 0, $method = '')
	{
		static $priority = 'db_warning';
		
		if (!self::getLogger()->hasWriter($priority)) {
			$table = 'logwf_' . date('Ym');
			
			$dbProxy = Util::getDbProxy(Constant::DB_CLUSTER_LOG);
			$writer = new LogDb($dbProxy->driver, $table, true);
			$writer->addPriority($priority);
			self::getLogger()->addWriter($writer, $priority);
		}
		
		self::write($priority, $event, $method, $errno);
	}
	
	/**
	 * 打印notice日志，日志存入数据库
	 * @param mixed $event
	 * @param string $method
	 * @return void
	 */
	public static function dbNotice($event, $method = '')
	{
		static $priority = 'db_notice';
		
		if (!self::getLogger()->hasWriter($priority)) {
			$table = 'log_' . date('Ymd');
		
			$dbProxy = Util::getDbProxy(Constant::DB_CLUSTER_LOG);
			$writer = new LogDb($dbProxy->driver, $table, true);
			$writer->addPriority($priority);
			self::getLogger()->addWriter($writer, $priority);
		}
	
		self::write($priority, $event, $method);
	}
}
